package com.lzh.others.basejava.Thread_21;

import lombok.SneakyThrows;

/**
 * @Classname Thread_01
 * @Description 线程基础
 * @Date 2021/9/13 14:05
 * @Created by liuzihao
 */
public class LiftOff implements Runnable {
    protected int countDown = 10;
    private static int taskCount = 0;
    private final int id = taskCount++;
    public LiftOff() {

    }

    public LiftOff(int countDown) {
        this.countDown = countDown;
    }

    public String status() {
        return "#" + id + "(" + (countDown > 0 ? countDown : "LiftOff!!!") + "),";
    }

    @SneakyThrows
    @Override
    public void run() {
        while ( countDown-- > 0){
            System.out.println(status());
            //对线程调度器的一种建议,向调度程序提示当前线程愿意放弃其当前对处理器的使用。
            Thread.sleep(500);
            Thread.yield();
        }
    }

    public static void main(String[] args) {
        LiftOff liftOff = new LiftOff();
        liftOff.run();
        Thread thread = new Thread(new LiftOff());
        thread.start();
        System.out.println("LiftOff Finished");

//        for (int i = 0; i < 5; i++) {
//            new Thread(new LiftOff()).start();
//        }
    }
}
